<?php

/**
 * contact : 刘经理 19326416371
 * company : 版权所属 四川北星惯牌科技有限公司
 **/

namespace app\common\model;

use think\Model;


class Member extends Model
{



    CONST IS_OUT = 1;
    CONST NO_OUT = 0;

    CONST BACKEND_SYSTEM_YES = 1;
    CONST BACKEND_SYSTEM_NO = 0;

    CONST STATE_SUCCESS = 1;
    CONST STATE_WRITE_OFF = 2;
    CONST PAY_STATE_SUCCESS = 1;
    CONST PAY_STATE_CANCEL = 2;

    CONST IS_SYSTEM_YES = 1;
    CONST IS_SYSTEM_NO = 0;

    // 表名
    protected $name = 'match_member';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'is_out_text',
        'create_time_text',
        'update_time_text'
    ];
    

    
    public function getIsOutList()
    {
        return ['0' => __('Is_out 0'), '1' => __('Is_out 1')];
    }


    public function getIsOutTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_out']) ? $data['is_out'] : '');
        $list = $this->getIsOutList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function match()
    {
        return $this->belongsTo('app\admin\model\Match', 'match_id', 'm_id', [], 'LEFT')->setEagerlyType(0);
    }


    public function user()
    {
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
